package com.gec.controller;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.alibaba.fastjson.JSONObject;
import com.gec.domain.PageBean;

/**
 * @author Aniki
 */
public abstract class BaseController {

    protected String packJSON( PageBean pBean ){
        JSONObject jsObj = new JSONObject();
        jsObj.put("code", "0");
        jsObj.put("msg", "");
        jsObj.put("count", pBean.getCount());
        jsObj.put("data", pBean.getList());
        return jsObj.toJSONString();
    }

    protected String setErrorMsg( Exception e ) {
        e.printStackTrace();
        JSONObject jsObj = new JSONObject();
        jsObj.put("result", "failed");
        jsObj.put("cause", e.getMessage());
        return jsObj.toJSONString();
    }

    /** now 方法 功能: 获取当前时间。*/
    protected String now(){
        SimpleDateFormat sdf =
                new SimpleDateFormat("HH:mm:ss");
        Date d = new Date();
        return sdf.format( d );
    }

}
